package io.itit.ecp.admin.provide.filter;

import com.alibaba.fastjson.serializer.ValueFilter;
import io.itit.grass.common.server.helper.DictHelper;
import io.itit.grass.common.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：预警推送键值转换
 * @Date：Create by 2023-12-15 10:51:22
 */
public interface IEarlyWarningPushFilter {

	String STATUS = "status" ;

	String EARLY_WARNING_PUSH_STATUS = "ecp-admin.earlyWarningPush.status" ;

	class EarlyWarningPushExportFilter implements ValueFilter {

		private Map<String, String> statusMap;

		public EarlyWarningPushExportFilter() {
			statusMap = DictHelper.i().stringVlMap(EARLY_WARNING_PUSH_STATUS);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, STATUS)) {
				return CommonUtils.orElse(statusMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

	class EarlyWarningPushUploadFilter implements ValueFilter {

		private Map<String, String> statusMap;

		public EarlyWarningPushUploadFilter() {
			statusMap = DictHelper.i().stringLvMap(EARLY_WARNING_PUSH_STATUS);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, STATUS)) {
				return CommonUtils.orElse(statusMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

}